//
//  YWTabBarController.m
//  通信录
//
//  Created by yellow on 16/6/29.
//  Copyright © 2016年 yellow. All rights reserved.
//

#import "YWTabBarController.h"

#import "YWPengyouquanController.h"
#import "YWDouyinController.h"
#import "YWQicheController.h"
#import "YWYoukuController.h"

#import "YWNavigationController.h"

#import "YWWeiboController.h"

@interface YWTabBarController ()<UITabBarDelegate>



@property (nonatomic, strong) YWYoukuController *youkuVC;
@property (nonatomic, strong) YWPengyouquanController *pengyouquanVC;
@property (nonatomic, strong) YWDouyinController *douyinVC;
@property (nonatomic, strong) YWQicheController *qicheVC;
@property (nonatomic, strong) YWWeiboController *weiboVC;



@end

@implementation YWTabBarController



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.tintColor = mainColor;
    self.tabBar.translucent = NO;
    [[UITabBar appearance] setBarTintColor: [UIColor whiteColor]];
    
    
    //初始化所有子控制器
    [self setupAllChildViewControllers];


}

-(void)setupAllChildViewControllers{
    
    YWPengyouquanController *pengyouquanVC = [[YWPengyouquanController alloc] initWithNibName:@"YWPengyouquanController" bundle:nil];
    [self setupChildViewController:pengyouquanVC title:@"朋友圈" imageName:@"直播未选中"  selectedImageName:@"直播选中"];
    self.pengyouquanVC = pengyouquanVC;
    
    
    YWQicheController *qicheVC = [[YWQicheController alloc] initWithNibName:@"YWQicheController" bundle:nil];
    [self setupChildViewController:qicheVC title:@"汽车之家" imageName:@"首页未选中"  selectedImageName:@"首页选中"];
    self.qicheVC = qicheVC;
    
    
    YWWeiboController *weiboVC = [[YWWeiboController alloc] initWithNibName:@"YWWeiboController" bundle:nil];
    [self setupChildViewController:weiboVC title:@"微博" imageName:@"VIP未选中"  selectedImageName:@"VIp选中"];
    self.qicheVC = qicheVC;
    
    YWDouyinController *douyinVC = [[YWDouyinController alloc] initWithNibName:@"YWDouyinController" bundle:nil];
    [self setupChildViewController:douyinVC title:@"抖音" imageName:@"自选未选中"  selectedImageName:@"自选选中"];
    self.douyinVC = douyinVC;
    
    YWYoukuController *youkuVC = [[YWYoukuController alloc] initWithNibName:@"YWYoukuController" bundle:nil];
    [self setupChildViewController:youkuVC title:@"优酷" imageName:@"我的未选中" selectedImageName:@"我的选中"];
    self.youkuVC = youkuVC;
    
}



-(void)setupChildViewController:(UIViewController*)childVc title:(NSString*)title imageName:(NSString*)imageName selectedImageName:(NSString*)selectedImageName{
    
    childVc.title = title;
    childVc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //改变图片位置
    [childVc.tabBarItem setImageInsets:UIEdgeInsetsMake(-1, 0, 1, 0)];
    
    
    //改变文字大小位置
    [childVc.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
    //Normal
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: YWColor(51, 51, 51),NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    
   
    
    //Selected
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: mainColor,NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];
    
    if ([title isEqualToString:@"微博"]) {

        //Selected
        [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor systemYellowColor],NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];
    }
    
    
    YWNavigationController *nav= [[YWNavigationController alloc] initWithRootViewController:childVc];

    [self addChildViewController:nav];
}


- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{

}

@end
